package cn.jantd.modules.system.controller;


import cn.jantd.core.annotation.AutoLog;
import cn.jantd.core.annotation.PermissionData;
import cn.jantd.core.api.vo.Result;
import cn.jantd.core.poi.def.NormalExcelConstants;
import cn.jantd.core.poi.excel.ExcelImportUtil;
import cn.jantd.core.poi.excel.entity.ExportParams;
import cn.jantd.core.poi.excel.entity.ImportParams;
import cn.jantd.core.poi.view.JantdEntityExcelViewBase;
import cn.jantd.core.system.query.QueryGenerator;
import cn.jantd.core.system.vo.LoginUser;
import cn.jantd.modules.system.entity.*;
import cn.jantd.modules.system.service.*;
import cn.jantd.modules.system.vo.SysTeamVo;
import cn.jantd.modules.system.vo.SysUserVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/**
 * <p>
 * 团队表 前端控制器
 * </p>
 *
 * @Author xiagf
 * @date 2019-07-04
 */
@Slf4j
@RestController
@RequestMapping("/sys/team")
public class SysTeamController {
    @Autowired
    private ISysTeamService sysTeamService;
    @Autowired
    private ISysTeamRoleService sysTeamRoleService;

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysRoleTeamuserService sysRoleTeamuserService;
    @Autowired
    private ISysTeamUserService teamUserService;

    /**
     * 分页列表查询
     *
     * @param team
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "团队管理-分页列表查询")
    @ApiOperation(value = "团队管理-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<SysTeamVo>> queryPageList(SysTeam team, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        Result<IPage<SysTeamVo>> result = new Result<>();
        QueryWrapper<SysTeam> queryWrapper = QueryGenerator.initQueryWrapper(team, req.getParameterMap());
        Page<SysTeam> page = new Page<>(pageNo, pageSize);
        IPage<SysTeam> pageList = sysTeamService.page(page, queryWrapper);
        IPage<SysTeamVo> voPage = new Page<>(pageNo, pageSize);
        voPage.setCurrent(pageList.getCurrent());
        voPage.setSize(pageList.getSize());
        voPage.setTotal(pageList.getTotal());
        voPage.setPages(pageList.getPages());
        ArrayList<SysTeamVo> list = new ArrayList<SysTeamVo>();
        ArrayList<SysTeam> teamlist = new ArrayList<SysTeam>();
        for (SysTeam team1 : pageList.getRecords()) {
            SysTeamVo teamVo = new SysTeamVo();
            teamVo.setId(team1.getId());
            //创建list存放用户数据：wb
                System.out.println("teamid是什么："+team1.getId());
            /*    SysTeamRole team2 = new SysTeamRole();*/
                /*   team2.setId(team1.getId());*/
                List<SysRoleTeamuser> teamroleList = sysRoleTeamuserService.getByTeamId(team1.getId());
                List<SysTeamUser> userList = teamUserService.getByTeamId(team1.getId());
                System.out.println("teamroleList："+teamroleList);
                if (teamroleList.size() > 0) {
                    StringBuffer s = new StringBuffer();
                    for (SysRoleTeamuser role : teamroleList) {
                        if (role != null) {
                            String teamRolename = sysTeamRoleService.getById(role.getTeamroleId()).getTeamRolename();
                            if(s.length() > 0){
                                s.append(",");
                            }
                            s.append(teamRolename);
                            System.out.println("看一看名称：++++++++++"+teamRolename);
                        }
                    }
                    teamVo.setTeamRolename(s.toString());
                }

            //new list
            ArrayList teamslist=new ArrayList();
            if (userList.size() > 0) {
                StringBuffer s = new StringBuffer();
                StringBuffer realNameS = new StringBuffer();
                for (SysTeamUser user : userList) {
                    if (user != null) {
                        String username = sysUserService.getById(user.getUserId()).getUsername();
                        String realName = sysUserService.getUserByName(username).getRealname();

                        String id=sysUserService.getById(user.getUserId()).getId();
                        teamVo.setTeamPlayerId(id);
                        if(s.length()>0){
                            s.append(",");
                        }
                        s.append(username);
                        if(realNameS.length()>0){
                            realNameS.append(",");
                        }
                        realNameS.append(realName);
                        Map<String,String> map = new HashMap<String,String>();
                        map.put("id",id);
                        map.put("username",username);
                        map.put("realName",realName);
                        teamslist.add(map);
                    }
                }
//                teamVo.setUsername(s.toString());
                teamVo.setUsername(realNameS.toString());
            }
            teamVo.setTeamPlayerList(teamslist);
            System.out.println("名称：++++++++++"+teamVo.getTeamPlayerList());
            teamVo.setCreateTime(team1.getCreateTime());
            teamVo.setUpdateTime(team1.getUpdateTime());
            teamVo.setTeamName(team1.getTeamName());
            list.add(teamVo);

        }




        voPage.setRecords(list);
        result.setSuccess(true);
        result.setResult(voPage);
        return result;
    }

    /*public Result<IPage<SysTeam>> queryPageList(SysTeam team, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        Result<IPage<SysTeam>> result = new Result<>();
        QueryWrapper<SysTeam> queryWrapper = QueryGenerator.initQueryWrapper(team, req.getParameterMap());
        Page<SysTeam> page = new Page<>(pageNo, pageSize);
        IPage<SysTeam> pageList = sysTeamService.page(page, queryWrapper);

        for (int i = 0; i < pageList.getRecords().size(); i++) {
            //创建list存放用户数据：wb
            ArrayList list = new ArrayList();
            for (SysTeam team1 : pageList.getRecords()) {
                System.out.println("teamid是什么："+team1.getId());
                SysTeamRole team2 = new SysTeamRole();
                *//*   team2.setId(team1.getId());*//*
                List<SysRoleTeamuser> teamroleList = sysRoleTeamuserService.getByTeamId(team1.getId());
                System.out.println("teamroleList："+teamroleList);
                if (teamroleList.size() > 0) {
                    String s = "";
                    for (SysRoleTeamuser role : teamroleList) {
                        if (role != null) {
                            String teamRolename = sysTeamRoleService.getById(role.getTeamroleId()).getTeamRolename();
                            s = teamRolename + "" + s;
                             System.out.println("看一看名称：++++++++++"+teamRolename);
                        }
                    }
                    team2.setTeamRolename(s);
                    list.add(team2);
                    System.out.println("list的内容："+list);
                }
            }

                String name = "";
                String player = pageList.getRecords().get(i).getTeamPlayer();
                String[] players = player.split(",");
                for (String p : players) {
                    if (sysUserService.getById(p) != null) {
                        SysTeam sysTeam = new SysTeam();
                        sysTeam.setTeamPlayerName(sysUserService.getById(p).getUsername());
                        sysTeam.setTeamPlayerId(p);
                        list.add(sysTeam);
                        //id 转用户名
                        name += sysUserService.getById(p).getUsername() + ",";
                    }
                }
                if (name.length() > 0 && name.substring(name.length() - 1).equals(",")) {
                    name = name.substring(0, name.length() - 1);
                }
                pageList.getRecords().get(i).setTeamPlayerName(name);
                pageList.getRecords().get(i).setTeamPlayerList(list);
            pageList.getRecords().get(i).setTeamPlayerList(list);

            }

        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }*/

    /**
     * 添加
     *
     * @param jsonObject
     * @return
     */
    @AutoLog(value = "团队管理-添加")
    @ApiOperation(value = "团队管理-添加")
    @PostMapping(value = "/add")
    public Result<SysTeam> add(@RequestBody JSONObject jsonObject) {
        Result<SysTeam> result = new Result<>();
             String selectedRolenames = jsonObject.getString("selectedrolenames");
             String selectedUsernames = jsonObject.getString("selectedusernames");
        try {
            SysTeam team = JSON.parseObject(jsonObject.toJSONString(), SysTeam.class);
            // 设置创建时间
            team.setCreateTime(new Date());
/*            if (team.getTeamPlayer() != "") {
                String[] players = team.getTeamPlayerName().split(",");
                String play = "";
                for (String p : players) {
                    if (sysUserService.getUserByName(p) != null)
                        play += sysUserService.getUserByName(p).getId() + ",";
                }
                if (play != "")
                    play = play.substring(0, play.length() - 1);
                team.setTeamPlayer(play);
            }*/
            sysTeamService.addTeamWithRole(team, selectedRolenames,selectedUsernames);
        /*    sysTeamService.save(team);*/
            result.success("添加成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        System.out.println("我想看看：+++++++++" + result);
        return result;

    }

    /**
     * 编辑
     *
     * @param jsonObject
     * @return
     */

    @AutoLog(value = "团队管理-编辑")
    @ApiOperation(value = "团队管理-编辑")
    @PutMapping(value = "/edit")
    public Result<SysTeam> edit(@RequestBody JSONObject jsonObject) {
        Result<SysTeam> result = new Result<>();
        try {
            SysTeam sysTeam = sysTeamService.getById(jsonObject.getString("id"));
            if (sysTeam == null) {
                result.error500("未找到对应实体");
            } else {
                SysTeam team = JSON.parseObject(jsonObject.toJSONString(), SysTeam.class);
                team.setUpdateTime(new Date());
  /*              String[] players = team.getTeamPlayerName().split(",");
                String playId = "";
                for (String player : players) {
                    if (sysUserService.getUserByName(player) != null) {
                        playId += sysUserService.getUserByName(player).getId() + ",";
                    }
                }
                if (playId.length() > 0) {
                    playId = playId.substring(0, playId.length() - 1);
                }
                team.setTeamPlayer(playId);*/
                String roles = jsonObject.getString("selectedrolenames");
                String names = jsonObject.getString("selectedusernames");
                System.out.println("kankan:"+names);
                sysTeamService.editTeamWithRole(team, roles,names);
                boolean ok = sysTeamService.updateById(team);
                if (ok) {
                    result.success("修改成功!");
                }
  /*              team.setPassword(sysUser.getPassword());
                String roles = jsonObject.getString("selectedroles");
                sysUserService.editUserWithRole(user, roles);*/
                result.success("修改成功!");
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }




    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "团队管理-通过id删除")
    @ApiOperation(value = "团队管理-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<SysTeam> delete(@RequestParam(name = "id", required = true) String id) {
        Result<SysTeam> result = new Result<>();
        // 定义SysUserDepart实体类的数据库查询LambdaQueryWrapper
        LambdaQueryWrapper<SysRoleTeamuser> sysRoleTeamuserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<SysTeamUser> sysTeamUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
        SysTeam sysTeam = sysTeamService.getById(id);
        if (sysTeam == null) {
            result.error500("未找到对应实体");
        } else {
            boolean ok = sysTeamService.removeById(id);
            // 当某个用户被删除时,删除其ID下对应的团队角色数据
            sysRoleTeamuserLambdaQueryWrapper.eq(SysRoleTeamuser::getTeamId, id);
            sysRoleTeamuserService.remove(sysRoleTeamuserLambdaQueryWrapper);
            sysTeamUserLambdaQueryWrapper.eq(SysTeamUser::getTeamId, id);
            teamUserService.remove(sysTeamUserLambdaQueryWrapper);
            if (ok) {
                result.success("删除成功!");
            }
        }

        return result;
    }

    /**
     * 批量删除用户
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "团队管理-批量删除")
    @ApiOperation(value = "团队管理-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<SysTeam> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        // 定义SysUserDepart实体类的数据库查询对象LambdaQueryWrapper

        String[] idArry = ids.split(",");
        Result<SysTeam> result = new Result<>();
        if (StringUtils.isEmpty(ids)) {
            result.error500("参数不识别！");
        } else {
            this.sysTeamService.removeByIds(Arrays.asList(ids.split(",")));
            // 当批量删除时,删除在SysUserDepart中对应的所有部门数据
            for (String id : idArry) {
                LambdaQueryWrapper<SysRoleTeamuser> sysRoleTeamuserLambdaQueryWrapper = new LambdaQueryWrapper<>();
                LambdaQueryWrapper<SysTeamUser> sysTeamUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
                sysRoleTeamuserLambdaQueryWrapper.eq(SysRoleTeamuser::getTeamroleId,id);
                sysTeamUserLambdaQueryWrapper.eq(SysTeamUser::getUserId,id);
                this.sysRoleTeamuserService.remove(sysRoleTeamuserLambdaQueryWrapper);
                this.teamUserService.remove(sysTeamUserLambdaQueryWrapper);
            }
            result.success("删除成功!");
        }
        return result;
    }

    /**
     * 冻结&解冻用户
     *
     * @param jsonObject
     * @return
     */
    /*@AutoLog(value = "团队管理-冻结&解冻用户")
    @ApiOperation(value = "团队管理-冻结&解冻用户")
    @PutMapping(value = "/frozenBatch")
    public Result<SysUser> frozenBatch(@RequestBody JSONObject jsonObject) {
        Result<SysUser> result = new Result<>();
        try {
            String ids = jsonObject.getString("ids");
            String status = jsonObject.getString("status");
            String[] arr = ids.split(",");
            for (String id : arr) {
                if (oConvertUtils.isNotEmpty(id)) {
                    this.sysUserService.update(new SysUser().setStatus(Integer.parseInt(status)),
                            new UpdateWrapper<SysUser>().lambda().eq(SysUser::getId, id));
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败" + e.getMessage());
        }
        result.success("操作成功!");
        return result;

    }*/

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "团队管理-通过id查询")
    @ApiOperation(value = "团队管理-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<SysTeam> queryById(@RequestParam(name = "id", required = true) String id) {
        Result<SysTeam> result = new Result<>();
        SysTeam sysTeam = sysTeamService.getById(id);
        if (sysTeam == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(sysTeam);
            result.setSuccess(true);
        }
        return result;
    }


    /**
     * 导出excel
     *
     * @param sysTeam
     * @param request
     * @return
     */
    @AutoLog(value = "团队管理-导出excel")
    @ApiOperation(value = "团队管理-导出excel")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(SysTeam sysTeam, HttpServletRequest request) {
        // Step.1 组装查询条件
        QueryWrapper<SysTeam> queryWrapper = QueryGenerator.initQueryWrapper(sysTeam, request.getParameterMap());
        //Step.2 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JantdEntityExcelViewBase());
        List<SysTeam> pageList = sysTeamService.list(queryWrapper);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "团队管理列表");
        mv.addObject(NormalExcelConstants.CLASS, SysTeam.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("团队管理列表数据", "导出人:" + user.getRealname(), "导出信息"));
        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
        return mv;
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @AutoLog(value = "团队管理-通过excel导入数据")
    @ApiOperation(value = "团队管理-通过excel导入数据")
    @PostMapping(value = "/importExcel")
    public Result<Object> importExcel(HttpServletRequest request, HttpServletResponse response) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<SysTeam> listSysTeams = ExcelImportUtil.importExcel(file.getInputStream(), SysTeam.class, params);
                for (SysTeam sysTeamExcel : listSysTeams) {

                    sysTeamService.save(sysTeamExcel);
                }
                return Result.ok("文件导入成功！数据行数：" + listSysTeams.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("抱歉! 您导入的数据中用户名已经存在.");
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
        return Result.error("文件导入失败！");
    }

    /**
     * 添加
     *
     * @param jsonObject
     * @return
     */
    @AutoLog(value = "团队管理-添加团队角色")
    @ApiOperation(value = "团队管理-添加团队角色")
    @PostMapping(value = "/addTeamrole")
    public Result<SysTeamRole> addTeamrole(@RequestBody JSONObject jsonObject) {
        Result<SysTeamRole> result = new Result<>();
        try {
            SysTeamRole team = JSON.parseObject(jsonObject.toJSONString(), SysTeamRole.class);
            sysTeamRoleService.save(team);
            result.success("添加成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        System.out.println("我想看看：+++++++++" + result);
        return result;
    }

/*
    *//**
     * 通过id查询
     *
     * @param id
     * @return
     *//*
    @AutoLog(value = "角色管理-通过id查询")
    @ApiOperation(value = "角色管理-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<SysRole> queryById(@RequestParam(name = "id", required = true) String id) {
        Result<SysRole> result = new Result<SysRole>();
        SysRole sysrole = sysRoleService.getById(id);
        if (sysrole == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(sysrole);
            result.setSuccess(true);
        }
        return result;
    }*/
    /**
     * 查询全部用户
     *
     * @return
     */
    @GetMapping(value = "/userall")
    public Result<List<SysUser>> userall() {
        Result<List<SysUser>> result = new Result<>();
        List<SysUser> list = sysUserService.list();
        System.out.println("这个是什么yonghu数据：+++++" + list.get(0).getUsername());
        if (list.isEmpty()) {
            result.error500("未找到用户信息");
        } else {
            result.setResult(list);
            result.setSuccess(true);
        }

        return result;
    }
    /**
     * 查询全部角色
     *
     * @return
     */
    @GetMapping(value = "/roleNameAll")
    public Result<List<SysTeamRole>> roleNameAll() {
        Result<List<SysTeamRole>> result = new Result<>();
        List<SysTeamRole> list = sysTeamRoleService.list();
        System.out.println("看看角色息是什么："+list.get(0).getTeamRolename());
        if (list.isEmpty()) {
            result.error500("未找到团队角色信息");
        } else {
            result.setResult(list);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * 通过userId查询用户角色
     *
     * @param teamid
     * @return
     */
    @AutoLog(value = "团队管理-通过teamId查询团队角色")
    @ApiOperation(value = "团队管理-通过teamId查询团队角色")
    @GetMapping(value = "/queryTeamRole")
    public Result<List<String>> queryTeamRole(@RequestParam(name = "teamid", required = true) String teamid) {
        Result<List<String>> result = new Result<>();
        List<String> list = new ArrayList<>();
        List<SysRoleTeamuser> teamRole = sysRoleTeamuserService.list(new QueryWrapper<SysRoleTeamuser>().lambda().eq(SysRoleTeamuser::getTeamId, teamid));
        if (teamRole.isEmpty()) {
            result.error500("未找到团队相关角色信息");
        } else {
            for (SysRoleTeamuser sysRoleTeamuser : teamRole) {
                list.add(sysRoleTeamuser.getTeamroleId());
            }
            result.setSuccess(true);
            result.setResult(list);
        }
        return result;
    }


    /*
    *
    * */

    @AutoLog(value = "角色管理-分页列表查询")
    @ApiOperation(value = "角色管理-分页列表查询")
    @GetMapping(value = "/getRolenameList")
    public Result<IPage<SysTeamRole>> getRolenameList(SysTeamRole role,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        Result<IPage<SysTeamRole>> result = new Result<IPage<SysTeamRole>>();
        QueryWrapper<SysTeamRole> queryWrapper = QueryGenerator.initQueryWrapper(role, req.getParameterMap());
        Page<SysTeamRole> page = new Page<SysTeamRole>(pageNo, pageSize);
        IPage<SysTeamRole> pageList = sysTeamRoleService.page(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }


    /**
     * 通过userId查询用户角色
     *
     * @param teamid
     * @return
     */
    @AutoLog(value = "团队管理-通过teamId查询用户")
    @ApiOperation(value = "团队管理-通过teamId查询用户")
    @GetMapping(value = "/queryTeamUser")
    public Result<List<String>> queryTeamUser(@RequestParam(name = "teamid", required = true) String teamid) {
        Result<List<String>> result = new Result<>();
        List<String> list = new ArrayList<>();
        List<SysTeamUser> teamUser = teamUserService.list(new QueryWrapper<SysTeamUser>().lambda().eq(SysTeamUser::getTeamId, teamid));
        if (teamUser.isEmpty()) {
            result.error500("未找到团队相关用户信息");
        } else {
            for (SysTeamUser sysTeamUser : teamUser) {
                list.add(sysTeamUser.getUserId());
            }
            result.setSuccess(true);
            result.setResult(list);
        }
        return result;
    }






    /**
     * 通过userId查询用户角色
     *
     * @param userid
     * @return
     */
  /*  @AutoLog(value = "用户管理-通过userId查询用户角色")
    @ApiOperation(value = "用户管理-通过userId查询用户角色")
    @GetMapping(value = "/queryUserRole")
    public Result<List<String>> queryUserRole(@RequestParam(name = "userid", required = true) String userid) {
        Result<List<String>> result = new Result<>();
        List<String> list = new ArrayList<>();
        List<SysUserRole> userRole = sysUserRoleService.list(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, userid));
        if (userRole.isEmpty()) {
            result.error500("未找到用户相关角色信息");
        } else {
            for (SysUserRole sysUserRole : userRole) {
                list.add(sysUserRole.getRoleId());
            }
            result.setSuccess(true);
            result.setResult(list);
        }
        return result;
    }
*/



    /*  *//**
     * 生成在添加用户情况下没有主键的问题,返回给前端,根据该id绑定部门数据
     *
     * @return
     *//*
    @ApiOperation(value = "用户管理-生成在添加用户情况下没有主键的问题,返回给前端,根据该id绑定部门数据")
    @GetMapping(value = "/generateUserId")
    public Result<String> generateUserId() {
        Result<String> result = new Result<>();
        log.info("我执行了,生成用户ID==============================");
        String userId = UUID.randomUUID().toString().replace("-", "");
        result.setSuccess(true);
        result.setResult(userId);
        return result;
    }
*/
    /**
     * 根据部门id查询用户信息
     *
     * @param id
     * @return
     */
  /*  @AutoLog(value = "用户管理-根据部门id查询用户信息")
    @ApiOperation(value = "用户管理-根据部门id查询用户信息")
    @GetMapping(value = "/queryUserByDepId")
    public Result<List<SysUser>> queryUserByDepId(@RequestParam(name = "id", required = true) String id) {
        Result<List<SysUser>> result = new Result<>();
        List<SysUser> userList = sysUserDepartService.queryUserByDepId(id);
        try {
            result.setSuccess(true);
            result.setResult(userList);
            return result;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setSuccess(false);
            return result;
        }
    }*/

    /**
     * 查询所有用户所对应的角色信息
     *
     * @return
     */
  /*  @AutoLog(value = "用户管理-查询所有用户所对应的角色信息")
    @ApiOperation(value = "用户管理-查询所有用户所对应的角色信息")
    @GetMapping(value = "/queryUserRoleMap")
    public Result<Map<String, String>> queryUserRole() {
        Result<Map<String, String>> result = new Result<>();
        Map<String, String> map = userRoleService.queryUserRole();
        result.setResult(map);
        result.setSuccess(true);
        return result;
    }
*/

    /**
     * @param userIds
     * @return
     * @功能：根据id 批量查询
     */
/*    @AutoLog(value = "用户管理-根据id 批量查询")
    @ApiOperation(value = "用户管理-根据id 批量查询")
    @GetMapping(value = "/queryByIds")
    public Result<Collection<SysUser>> queryByIds(@RequestParam String userIds) {
        Result<Collection<SysUser>> result = new Result<>();
        String[] userId = userIds.split(",");
        Collection<String> idList = Arrays.asList(userId);
        Collection<SysUser> userRole = sysUserService.listByIds(idList);
        result.setSuccess(true);
        result.setResult(userRole);
        return result;
    }*/


    /**
     * 根据角色Id查询用户
     *
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
/*    @AutoLog(value = "用户管理-根据角色Id查询用户")
    @ApiOperation(value = "用户管理-根据角色Id查询用户")
    @GetMapping(value = "/userRoleList")
    public Result<IPage<SysUser>> userRoleList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        Result<IPage<SysUser>> result = new Result<>();
        Page<SysUser> page = new Page<>(pageNo, pageSize);
        String roleId = req.getParameter("roleId");
        String username = req.getParameter("username");
        IPage<SysUser> pageList = sysUserService.getUserByRoleId(page, roleId, username);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }
    */




}
